package com.hmall.item.task;

import com.hmall.item.pojo.Item;
import com.hmall.item.service.impl.ItemService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * TODO
 *
 * @Author lyh
 * @Date 2024/11/13 21:43
 */
@Component
public class Top20 {
    @Autowired
    private ItemService itemService;
    @Autowired
    private RedisTemplate redisTemplate;
    @Scheduled(cron = "0 0 */1 * * ?")
    public void getTop20(){
      System.out.println("定时任务开始");
      List<Item> list=itemService.getTop20();
      redisTemplate.opsForValue().set("top20",list);
    }
}
